package com.yuwj.chinaa.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.yuwj.chinaa.R;
import com.yuwj.chinaa.base.BaseActivity;
import com.yuwj.chinaa.base.ConstantParam;
import com.yuwj.chinaa.util.ClipboardUtil;
import com.yuwj.chinaa.util.ToastUtil;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import butterknife.BindView;
import butterknife.OnClick;

//分享推广界面
public class ShareGeneralizeActivity extends BaseActivity{
    @BindView(R.id.tv_inv_code)
    TextView tvInvCode;
    @BindView(R.id.iv_qrcode)
    ImageView ivQrCode;


    @Override
    public int setCustomContentViewResourceId() {
        return R.layout.activity_share_generalize;
    }

    public static Intent createIntent(Context context) {
        Intent intent = new Intent(context, ShareGeneralizeActivity.class);
        return intent;
    }


    @Override
    public void initParam() {

    }

    @Override
    public void initView() {
        tvInvCode.setText(entityUser.getInvitationCode());
        String shareUrl="http://chinaa.zhimabaobao.com/home/register/"+entityUser.getInvitationCode();
        Bitmap bitmapWithQRCode = CodeUtils.createImage(shareUrl, 400, 400, null);
        if (bitmapWithQRCode != null) {
            ivQrCode.setImageBitmap(bitmapWithQRCode);
        } else {
            ToastUtil.getInstance().shortLength(context, "二维码生成失败");
        }
    }

    @Override
    public void initOperator() {

    }
    @OnClick({ R.id.ll_copy,R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
//            case R.id.tv_save_qrcode:
//                if (bitmapWithQRCode != null) {
//                    //首先创建下载目录
//                    String path = ConstantParam.DOWNLOAD_FILE_PATH;
//                    File dir = new File(path);
//                    if (!dir.exists()) {
//                        dir.mkdirs();
//                    }
//                    //下载目录下的收款图片地址
//                    String filePic = ConstantParam.DOWNLOAD_FILE_PATH + "充值地址.jpg";
//                    try {
//                        FileOutputStream fos = new FileOutputStream(filePic);
//                        bitmapWithQRCode.compress(Bitmap.CompressFormat.JPEG, 100, fos);
//                        fos.flush();
//                        fos.close();
//                        ToastUtil.getInstance().shortLength(context, "文件已保存到" + filePic);
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                        ToastUtil.getInstance().shortLength(context, "文件保存失败");
//                    }
//                }
//                break;
            case R.id.ll_copy:
                String inviteCode = tvInvCode.getText().toString();
                ClipboardUtil.copyText(context, inviteCode);
                ToastUtil.getInstance().shortLength(context, "复制成功");
                break;
        }
    }


}
